#ifndef BITMAP_HPP
#define BITMAP_HPP

#include "basic_primitives.hpp"
#include "blitters.hpp"
#include <vl/rect.hpp>

#include <iostream>

template< typename ColorT >
class Bitmap
{
	public:
	typedef ColorT ColorType;
	
	Bitmap( unsigned int width, unsigned int height )
		: w( width ), h( height ), clip( 0, 0, width, height )
	{
		pitch = width * SizeOfPixel;
		pitch += 3 - ( ( pitch - 1 ) & 3 ); // 4 bytes align
		dataSize = pitch * height;
		data = new unsigned char[dataSize];
	}
	
	Bitmap( unsigned int width, unsigned int height, ColorT color )
		: w( width ), h( height ), clip( 0, 0, width, height )
	{
		pitch = width * SizeOfPixel;
		pitch += 3 - ( ( pitch - 1 ) & 3 ); // 4 bytes align
		dataSize = pitch * height;
		data = new unsigned char[dataSize];
		CopyBlitter< ColorT > b;
		blendToColor( this, color, b );
	}
	
	inline ColorT& at( unsigned int x, unsigned int y )
	{
		return data[ x + y*pitch ];
	}
	
	inline const ColorT& at( unsigned int x, unsigned int y ) const
	{
		return data[ x + y*pitch ];
	}
	
	~Bitmap()
	{
		delete[] data;
	}
	
	std::size_t w;			// bitmap width
	std::size_t h;			// bitmap height
	std::size_t pitch;		// size distance from one line to the other in bytes
	unsigned char* data;	// bitmap data
	std::size_t dataSize;	// bitmap data size in bytes
	vl::rect clip;			// clip area
	
	static const std::size_t SizeOfPixel = sizeof( ColorType );
	
	
};

#endif // BITMAP_HPP
